# 目标： 学生管理系统
# 学生 / 老师 / 课程 /班级 四大类
from webcolors import names


# 学生和老师的基类
class User(object):
    def __init__(self,name,age,gender,id_number):
        self.name = name.title()
        self.age = age
        self.gender = gender
        self.id_number = id_number

    def show_infos(self):
        print('*'*30)
        print(f"姓名：{self.name}")
        print(f"年龄：{self.age}")
        print(f"性别：{self.gender}")
        print(f"学(工)号：{self.id_number}")
        print('*'*30)

class Student(User):
    # 属性：姓名 / 年龄 / 性别 / 学号 / 选择课程
    def __init__(self,name,age,gender,id_number):
        super().__init__(name,age,gender,id_number)
        self.courses = []

    def show_infos(self):
        super().show_infos()
        print(f"{self.name}的选课信息为：",end=" ")
        if self.courses:
            for i in self.courses:
                print(i.name,end=" ")
        else:
            print("空")
            print(len(self.courses))

    def add_course(self,course):
        self.courses.append(course)

class Teacher(User):
    # 属性： 姓名/年龄/性别/工号/ 是否导员
    def __init__(self,name,age,gender,id_number,position_flag=False):
        super().__init__(name,age,gender,id_number)
        if position_flag:
            self.flag = True
            input_str = input("请输入该导员所带班级(空格分隔班级)：")
            classrooms = input_str.split(' ')
            self.classrooms = classrooms
        else:
            self.flag = False

    def show_infos(self):
        super().show_infos()
        if self.flag:
            print(f"是否为导员：是")
            print("管理班级：")
            for i in self.classrooms:
                print(f"{i}班")
        else:
            print(f"是否为导员：否")
        print('*'*30)

class Classroom(object):
    # 属性：班级名称 / 班级号/ 辅导员 / 学生
    def __init__(self,name,id_number,teacher,students):
        self.name = name
        self.id_number = id_number
        self.teacher = teacher
        self.students = students

    def show_infos(self):
        print('*'*15+'班级信息'+'*'*15)
        print(f"班级名称： {self.name}")
        print(f"班级班号: {self.id_number}")
        print(f"辅导员： {self.teacher.name}")
        print("学生信息：")
        if not self.students:
            print("空")
        else:
            for i in self.students:
                print(i.name)

    # 新增学员
    def add_student(self,student):
        if student in self.students:
            raise Exception("成员已加入该班级!")
        else:
            self.students.append(student)
            return True

    # 删除学员
    def sub_student(self,student):
        if student in self.students:
            self.students.remove(student)
            return True
        else:
            raise Exception("删除学员不在该班级内!")

class Course(object):
    # 属性： 课程名字 / 课程ID / 授课老师 / 学生列表 / 课程性质 / 课程容量 / 已选名额 / 剩余名额
    # 类属性：课程列表
    school_courses = []
    def __init__(self,name,id,teacher,students,describe,number):
        self.name = name
        self.id = id
        self.teacher = teacher
        self.students = students
        self.describe = describe
        self.number = number
        self.selected = len(self.students)
        self.valid_num = self.number - self.selected

        Course.school_courses.append(self)

    def show_infos(self):
        print(f"课程名：{self.name}")
        print(f"课程编号： {self.id}")
        print(f"授课老师： {self.teacher.name}")
        print(f"课程描述： {self.describe}")
        print(f"课程容量： {self.number}")
        print(f"已选学生数量： {self.selected}")
        print(f"课程剩余容量： {self.valid_num}")
        print("课程参与学生：")
        if not self.students:
            print("空")
        else:
            for i in self.students:
                print(i.name)

    # 学生选课
    def add_student(self,student):
        if student in self.students:
            raise Exception("该学生已经参与本课程，加入错误!")
        else:
            self.students.append(student)
            self.valid_num -= 1
            self.selected += 1
            student.add_course(self)
            return True

    # 学生退课
    def sub_student(self,student):
        if student not in self.students or not self.students:
            raise Exception("学生未参与该门课程，退出错误!")
        else:
            self.students.remove(student)
            self.valid_num += 1
            self.selected -= 1
            return True

    @classmethod
    def show_courseList(cls):
        print("学校提供的课程为：")
        if not cls.school_courses:
            print("空")
        else:
            list = []
            for i in cls.school_courses:
                list.append(i.name)
            return list



# 学生
mia = Student('mia',24,'女',1)
user = Student('marry',22,"女",9)
tim = Student('tim',22,"男",19)

# 老师
jack = Teacher('jack',24,'女',2)

# 班级
c2 = Classroom("计算机二班",1002,jack,[mia,user])

# 课程
python = Course('python',1,jack,[mia,tim],"必修课",50)

java = Course('java',2,jack,[],"选修课",5)

print(Course.show_courseList())

